package com.insurance.controller;

import com.insurance.domain.ResponseResult;
import com.insurance.domain.entity.Customer;
import com.insurance.domain.entity.Guarantee;
import com.insurance.domain.enums.AppHttpCodeEnum;
import com.insurance.domain.vo.CustomerPageVo;
import com.insurance.domain.vo.GuaranteePageVo;
import com.insurance.service.CustomerService;
import com.insurance.service.GuaranteeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author qcjstudy
 * @create 2023-04-22 9:56
 */
@RestController
@RequestMapping("/api/guarantee")
public class GuaranteeController {

    @Autowired
    private GuaranteeService guaranteeService;
    private GuaranteePageVo guaranteePageVo;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody GuaranteePageVo guaranteePageVo){
        this.guaranteePageVo = guaranteePageVo;
        return guaranteeService.listByPage(guaranteePageVo);
    }

    @PostMapping()
    public ResponseResult add(@RequestBody Guarantee guarantee){
        return guaranteeService.addGuarantee(guarantee);
    }

    @PutMapping("/update")
    public ResponseResult update(@RequestBody Guarantee guarantee){
        return guaranteeService.updateGuarantee(guarantee);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        if(guaranteeService.removeById(id)){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.DELETE_FAILED);
    }
}
